﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace XEvents.Library
{
    public class Type : XEObjectBase
    {
        internal Type(dm_xe_object obj, SqlServer server)
            : base(obj, server)
        { }

        private Type()
            : base(null)
        { }

        public override string ToString()
        {
            return this.type_name;
        }

        public System.Type DataType
        {
            get
            {
                System.Type t;
                switch (this.type_name)
                {
                    case "null":
                        t = typeof(Nullable);
                        break;
                    case "int8":
                    case "int16":
                        t = typeof(Int16);
                        break;
                    case "int32":
                        t = typeof(Int32);
                        break;
                    case "int64":
                        t = typeof(Int64);
                        break;
                    case "uint8":
                    case "uint16":
                        t = typeof(UInt16);
                        break;
                    case "uint32":
                        t = typeof(UInt32);
                        break;
                    case "uint64":
                        t = typeof(UInt64);
                        break;
                    case "float32":
                    case "float64":
                        t = typeof(float);
                        break;
                    case "char":
                    case "wchar":
                        t = typeof(Char);
                        break;
                    case "guid":
                        t = typeof(Guid);
                        break;
                    case "boolean":
                        t = typeof(Boolean);
                        break;
                    case "binary_data":
                    case "callstack":
                    case "activity_id":
                    case "activity_id_xfer":
                    case "ansi_string":
                    case "unicode_string":
                    case "cpu_cycle":
                    case "filetime":
                    case "ulong_ptr":
                    case "ansi_string_ptr":
                    case "unicode_string_ptr":
                    case "guid_ptr":
                    case "database_context":
                    case "sos_context":
                    default:
                        t= typeof(string);
                        break;
                }
                return t;
            }
        }

        /// <summary>
        /// Size
        /// </summary>
        public int Size
        {
            get
            {
                return type_size;
            }
        }
    }
}
